Page({
  data: {
    ids:[],
    messages: [
      {
        id: '',
        annTime: '',
        announcement: '',
        isnew: ''
      }
     
      // 更多消息
    ],
    showModal: false
  },
  onNavigate(){
    wx.navigateBack({	  
      delta: 1
    })
  },

  onLoad: function (options) {
    this.informInfo();
      // 启动定时器定期刷新数据
      setInterval(() => {
        this.informInfo();
      }, 5000); // 每隔5秒钟刷新一次数据
      },
      informInfo: function () {
        wx.request({
          url: 'http://localhost:8080/keep/inform/status/'+getApp().globalData.loginfo.userId,
          method:'GET',
                header:{
                  'Authorization':getApp().globalData.authorization
                },
          success:resp=>{
              this.setData({
                messages:resp.data.data
              })
              
            
             },
          fail:resp=>{
              wx.showToast({
                title: '加载失败',
              })
          },
          complete:resp=>{}
        })
      },
   
  // 点击清空按钮时显示模态弹窗
  onClearMessages() {
    this.setData({
      showModal: true
    });

  },

  // 隐藏模态弹窗
  hideModal() {
    this.setData({
      showModal: false
    });
  },

  // 确认清空消息
  clearAllMessages() {
    wx.request({
      url: 'http://localhost:8080/keep/informisnew/update/del',
      method:'PUT',
      data:{
        userid:getApp().globalData.loginfo.userId
      },
            header:{
              'Authorization':getApp().globalData.authorization
            },
      success:resp=>{
        this.setData({
          messages: [],  // 清空消息数据
          showModal: false  // 隐藏模态弹窗
        });
         },
      fail:resp=>{
          wx.showToast({
            title: '加载失败',
          })
      },
    })
      
  }
  

    })
